// 全局共享数据示例
import { DEFAULT_NAME } from '@/constants/index';
import { getSelectCityList } from '@/servers/api/base';
import { getBannerScroll } from '@/servers/api/other';
import { useState } from 'react';

const useGlobal = () => {
    const [name, setName] = useState<string>(DEFAULT_NAME);
    const [bannerText, setBannerText] = useState<Array<string>>(["系统通知!!!!!"]);
    const [cityOptions, setcityOptions] = useState([]);
    function getCityList() {
        if (cityOptions.length > 0) {
            return;
        }
        getSelectCityList().then(res => {
            setcityOptions(res.data);
        })
    }
    function getBannerText(){
        getBannerScroll().then(res=>{
            setBannerText(res.data)
        })
    }
    return {
        name,
        setName,
        bannerText,
        setBannerText,
        cityOptions,
        setcityOptions,
        getCityList,
        getBannerText
    };
};

export default useGlobal;
